package top.malaoshi.webmvc.annotation.handler;

import org.springframework.web.bind.annotation.RequestMapping;

public class RequestMappingHandler {

    private RequestMapping requestMapping;

    public void setRequestMapping(RequestMapping requestMapping) {
        this.requestMapping = requestMapping;
    }

    /**
     * 返回所有的value和path
     * @return
     */
    public String[] getValueAndPath(){
        String[] values = null;
        if (requestMapping.value()!=null && requestMapping.value().length>0) {
            values = requestMapping.value();
        }
        String[] paths = null;
        if (requestMapping.path()!=null && requestMapping.path().length>0) {
            paths = requestMapping.path();
        }
        int valuesLen = 0;
        int pathLen = 0;
        if(values != null && values.length > 0){
            valuesLen = values.length;
        }
        if(paths != null && paths.length > 0){
            pathLen = paths.length;
        }
        String[] ret = new String[valuesLen + pathLen];
        if(valuesLen>0) {
            System.arraycopy(values, 0, ret, 0, values.length);
        }
        if(pathLen>0) {
            System.arraycopy(paths, 0, ret, values.length, paths.length);
        }

        return ret;
    }
}
